package com.protocolterminal.AFN.entity;

import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.List;

import com.protocolterminal.function.FrameFunction;

public class AFN0DF221 implements Interface_Data {

	@Override
	public String frametolist(String frame) throws Exception {
		List<String> list = new ArrayList<>();

		FrameFunction frameFunction = new FrameFunction();
		// 时标
		list.add(frameFunction.Reverse(frame.substring(0, 6)));
		// 抄表时间
		list.add(frameFunction.Reverse(frame.substring(6, 16)));

		DecimalFormat df = new DecimalFormat("######0.00");

		String svalue = frameFunction.Reverse(frame.substring(20, 28));
		svalue = svalue.replace("EE", "00");
		Double value = Double.valueOf(svalue) / 10000;
		list.add(df.format(value));

		String data = "";
		for (String string : list) {
			data += string + "-";
		}

		return data.substring(0, data.length() - 1);
	}

	@Override
	public String listtoframe(List<String> datalist) throws Exception {
		if (datalist.size() != 3) {
			return null;
		}

		String data = datalist.get(2) + datalist.get(1) + datalist.get(0);

		return data;
	}

}
